 <template>
   <el-card shadow="always" class="box-card">
      <div class="card-name search-item">
        <div class="name width2">物流公司</div>
        <div class="mr-30">
          <el-button size="medium" type="primary" @click="add">添加物流公司</el-button>
        </div>
      </div>
      <div class="content-con">
        <el-form :model="form" ref="form" class="bank-search">
          <el-form-item prop="keywords">
            <el-input v-model="form.keywords" placeholder="请输入物流公司名称或编目"></el-input>
          </el-form-item>
          <el-button class="save mb-22 ml-15" @click="search()">搜 索</el-button>
        </el-form>

        <div class="bank-form">
          <div class="form-item">
            <el-table
              :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              class="table"
              stripe border
              :header-cell-style="{background:'#f3f3f3',textAlign: 'center'}"
              :cell-style="{ textAlign: 'center' }">
              <el-table-column prop="no" label="编号" width="80">
              </el-table-column>
              <el-table-column prop="express" label="物流公司名称">
              </el-table-column>
              <el-table-column prop="catalog" label="编目">
              </el-table-column>
              <el-table-column prop="status" label="状态" width="160">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.status == 0" type="success">启用</el-tag>
                  <el-tag v-if="scope.row.status == 1" type="danger">停止</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button type="text" @click="handleEdit(scope.row)">
                    <i class="el-icon-edit"></i>编辑
                  </el-button>
                  <el-button type="text" @click.native.prevent="deleteRow(scope.$index,tableData)">
                    <i class="el-icon-delete"></i>删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!-- 分页-页码 -->
          <div class="page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="tableData.length">
            </el-pagination>
          </div>
        </div>
      </div>
      <express-edit ref="ExpressEdit" :rows="rows"></express-edit>
   </el-card>

 </template>
<script>
import ExpressEdit from '@/components/logistics/ExpressEdit';
export default {
  components:{
    ExpressEdit
  },
  data () {
    return {
      rows: '',
      currentPage: 1, //当前页码
      pagesize: 5,    //每页的数据条数
      tableData: [
        {
          no: '1',
          express: '中通快递',
          catalog: 'zhongtong',
          status: 1
        },
        {
          no: '2',
          express: '顺丰快递',
          catalog: 'shunfeng',
          status: 0
        },
        {
          no: '3',
          express: '中国邮政',
          catalog: 'intmail',
          status: 0
        }
      ],
      form: {
        keywords: ''
      }
    }
  },

  methods: {
    //搜索
    search() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log(this.form)
          this.$message.success('成功!');
        } else {
          console.log('error submit!!');
          this.$message.error('失败!');
          return false;
        }
      });
    },

    // 新增
    add(){
      this.$nextTick(()=>{
        this.$refs.ExpressEdit.openAdd();
      });
    },

    //编辑操作
    handleEdit(row){
      this.rows = row;
      this.$nextTick(()=>{
        this.$refs.ExpressEdit.openEdit();
      });
    },

    //删除操作
    deleteRow(index, rows){
      rows.splice(index, 1);
    },

    //每页条数改变时触发事件,选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pagesize = val;
    },
    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    }
  }
}
</script>
<style lang="scss">

</style>
